package cn.shujuhai.common.domain;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.validation.annotation.Validated;

import java.util.Date;
import java.util.List;

/**
 * 用户表
 *
 * @TableName sys_user
 */
@EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_user")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Validated
public class SysUser extends BaseDomain {

    public interface CreateGroup {
    }

    public interface UpdateGroup {
    }

    /**
     *
     */
    @TableId(type = IdType.AUTO)
    private Long userId;
    /**
     * 姓名
     */
    @ExcelProperty("姓名")
    @NotNull(message = "姓名不能为空", groups = {CreateGroup.class, UpdateGroup.class})
    private String name;

    /**
     * 用户名
     */
    @ExcelProperty("用户名")
    @NotNull(message = "用户名不能为空", groups = {CreateGroup.class})
    @Size(max = 15, message = "用户名长度必须在3到15个字符之间")
    @Pattern(regexp = "^[a-zA-Z0-9][a-zA-Z0-9_]*$", message = "用户名只能是字母、数字和下划线，且不能以下划线开始")
    private String username;

    /**
     * 密码
     */
    @NotNull(message = "密码不能为空", groups = {CreateGroup.class})
    @Size(min = 6, max = 20, message = "密码长度必须在6到20个字符之间")
    @Pattern(regexp = "/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[~!@&%#_])[a-zA-Z0-9~!@&%#_]{6,20}$/",
            message = "密码必须包含至少一个大写字母、一个小写字母、一个数字和一个特殊字符")
    private String password;
    /**
     * 年龄
     */
    @ExcelProperty("年龄")
    @NotNull(message = "年龄不能为空", groups = {CreateGroup.class, UpdateGroup.class})
    private Integer age;

    /**
     * 邮箱
     */
    @ExcelProperty("邮箱")
    @Email(message = "邮箱格式不正确", groups = {CreateGroup.class, UpdateGroup.class})
    private String email;

    /**
     * 电话
     */
    @ExcelProperty("电话")
    @NotNull(message = "手机号不能为空", groups = {CreateGroup.class, UpdateGroup.class})
    @Pattern(regexp = "^[0-9]{11}$", message = "手机号码格式不正确")
    private String phone;

    /**
     * 地区
     */
    private String area;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 性别： 1为男，2为女
     */
    @ExcelProperty("性别")
    @NotNull(message = "性别不能为空", groups = {CreateGroup.class, UpdateGroup.class})
    @Pattern(regexp = "^[12]$", message = "性别只能为字符串或者数字的1，2")
    private Integer sex;
    /**
     * 禁用状态：0启用，1禁用
     */
    private Integer status;
    /**
     * 用户最后修改密码时间
     */
    @TableField("last_password_change_date")
    private Date lastPasswordChangeDate;
    @TableField(exist = false)
    private List<Long> roleIds;

    @TableField(exist = false)
    private List<SysRole> roles;
    @TableField(exist = false)
    private List<Department> departmentList;
    @TableField(exist = false)
    private List<Long> departmentIds;
    @TableField("last_password_expire_prompt_count")
    private Integer passwordExpirePromptCount;

    private Boolean isPasswordChangeRequired;
}